import 'package:flutter/material.dart';
import 'package:flutter3demo/%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB/%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB%E4%B8%8D%E6%94%AF%E6%8C%81%E6%89%8B%E5%8A%BF%E6%BA%90%E7%A0%81/open_container.dart';


void main() {
  runApp(
    const MaterialApp(
      home: Page1(),
    ),
  );
}


class Page1 extends StatefulWidget {
  const Page1({super.key});

  @override
  State<StatefulWidget> createState() {
    return Page1State();
  }

}

class Page1State extends State<Page1> with TickerProviderStateMixin {
  late final AnimationController _controller = AnimationController(
    duration: const Duration(seconds: 2),
    vsync: this,
  )..repeat(reverse: true);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        color: Colors.red,
        child: OpenContainer(
          transitionDuration: const Duration(milliseconds: 500),
          // 打开状态
          openBuilder: (BuildContext context, VoidCallback _) {
            return const Page2();
          },
          // 闭合状态
          closedBuilder: (BuildContext context, VoidCallback openContainer) {
            return GestureDetector(
              onTap: openContainer,
              child: Container(
                width: 200,
                height: 200,
                color: Colors.blue,
                child: const Center(
                  child: Text(
                    'Tap to Open',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                    ),
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );
  }

  Route _createRoute() {

    double start = 0;
    double end = 50;
    const double smallLogo = 100;
    const double bigLogo = 200;
    return PageRouteBuilder(
      pageBuilder: (context, animation, secondaryAnimation) => const Page2(),
      transitionsBuilder: (context, animation, secondaryAnimation, child) {

        {

          return ScaleTransition(
            scale: Tween<double>(
              begin: 0.5,
              end: 1.0,
            ).chain(CurveTween(curve: Curves.ease)).animate(animation),
            alignment: Alignment.topRight,
            child: child,
          );
        }

        {
          var begin = 0.0;
          const end = 1.0;
          const curve = Curves.ease;

          final tween = Tween(begin: begin, end: end);
          final curvedAnimation = CurvedAnimation(
            parent: animation,
            curve: curve,
          );
          return ScaleTransition(
            scale: tween.animate(curvedAnimation),
            child: child,);
        }
        return Container();
        const begin = Offset(0.0, 1.0);
        const end = Offset.zero;
        const curve = Curves.ease;

        final tween = Tween(begin: begin, end: end);
        final curvedAnimation = CurvedAnimation(
          parent: animation,
          curve: curve,
        );
        return SlideTransition(

          position: tween.animate(curvedAnimation),
          child: child,);
      },
    );
  }

}



class Page2 extends StatelessWidget {
  const Page2({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        color: Colors.blue,
        child: const Center(
          child: Text('Page 2'),
        ),
      ),
    );
  }
}